package com.gitee.wsl.security.encrypt.sm4.service

import com.gitee.wsl.security.encrypt.sm4.SM4Utils

/**
 * @author cqp
 * @version 1.0.0
 * @ClassName SM4ServiceImpl.java
 * @Description TODO
 * @createTime 2021年04月22日 14:09:00
 */
class SM4ServiceImpl : SM4Service {
    var sm4: SM4Utils = SM4Utils()

    override fun encrypt_ECB(message: String): String? {
        sm4.secretKey = "64EC7C763AB7BF64E2D75FF83A319918"
        sm4.hexString = true
        return sm4.encryptData_ECB(message)
    }

    override fun decrypt_ECB(cipherText: String): String? {
        sm4.secretKey = "64EC7C763AB7BF64E2D75FF83A319918"
        sm4.hexString = true
        return sm4.decryptData_ECB(cipherText)
    }

    override fun encrypt_CBC(message: String): String? {
        sm4.iv = "31313131313131313131313131313131" // 初始变量
        return sm4.encryptData_CBC(message)
    }

    override fun decrypt_CBC(cipherText: String): String? {
        sm4.iv = "31313131313131313131313131313131"
        return sm4.decryptData_CBC(cipherText)
    }
}
